package com.venom.pizza.controller;

import com.venom.pizza.entities.Category;
import com.venom.pizza.repositories.CategoryRepository;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author denis
 */
@Controller
public class HelloWorldController {
    private CategoryRepository categoryRepository;
    
    @Autowired
    public void setCategoryRepository(CategoryRepository categoryRepository) {
        this.categoryRepository = categoryRepository;
    }

    @RequestMapping("/hello")
    public ModelAndView helloWorld() {
        List<Category> cats = categoryRepository.fetchAll();
        
        ModelMap map = new ModelMap();
        map.addAttribute("message", "Hello World, Spring 3.0!");
        map.addAttribute("cats", cats);
        
        return new ModelAndView("hello", map);
    }
    
}
